package com.java.simple.study.jvm.memstruct.directmemory;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhoujunlin
 * @date 2021/12/14
 * @desc 演示直接内存溢出
 **/
public class Demo4_2 {

    // 100MB
    private static final int _100MB = 1024 * 1024 * 100;

    public static void main(String[] args) {
        List<ByteBuffer> byteBufferList = new ArrayList<>();
        int i = 0;
        try {
            while (true) {
                final ByteBuffer byteBuffer = ByteBuffer.allocateDirect(_100MB);
                byteBufferList.add(byteBuffer);
                i++;
            }
        } catch (Throwable t) {
            t.printStackTrace();
        } finally {
            System.out.println("运行次数：" + i);
        }
    }
}
